﻿using AjaxControlToolkit;
using ASP;
using IPMS.AccessAuth;
using IPMS.BLL;
using IPMS.Sort;
using IPMS.Common;
using System;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Resources;
using System.Web;
using SysOperationLayer.DBHandle;
using System.Data;
using SysComm;


public partial class OptProductAdd : Page, IRequiresSessionState
{
    LogDB m_logdb = new LogDB();
    ProductDB m_productdb = new ProductDB();


    protected override void InitializeCulture()
    {
        string sCulture = ConfigurationManager.AppSettings["DefaultCulture"].ToString();
        try
        {
            sCulture = this.Session["Culture"].ToString();
        }
        catch (NullReferenceException)
        {
        }
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sCulture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(sCulture);
        base.InitializeCulture();
    }


    private void clearText()
    {
        this.txtModel.Text = string.Empty;
        this.txtRevision.Text = string.Empty;
        this.txtModelName.Text = string.Empty;
        this.txtSpecification.Text = string.Empty;
        //this.txtCreateDate.Text = string.Empty;
        this.txtRemarks1.Text = string.Empty;
        this.txtRemarks2.Text = string.Empty;
        this.txtRemarks3.Text = string.Empty;
        this.txtRemarks4.Text = string.Empty;
        this.txtRemarks5.Text = string.Empty;
        this.txtDate1.Text = string.Empty;
        this.txtDate2.Text = string.Empty;
        this.txtDate3.Text = string.Empty;
        this.txtDate4.Text = string.Empty;
        this.txtDate5.Text = string.Empty;
        this.txtDeci1.Text = string.Empty;
        this.txtDeci2.Text = string.Empty;
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!SysUtil.IsAdministratorOrNormalUserType())
        {
            base.Response.Redirect("ErrorPage/NotAllowed.aspx");
            return;
        }
        if (!IsPostBack)
        {
            ((Label)this.Master.FindControl("lblMstTitle")).Text = "| " + ISitemap.ProductManage.ToString() + " | " + ISitemap.NewProduct.ToString();
        }
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        int ret;
        ret = m_productdb.insertProduct(txtModel.Text.Trim(),
                                    txtModelName.Text.Trim(),
                                    txtRevision.Text.Trim(),
                                    txtSpecification.Text.Trim(),
                                    txtRemarks1.Text.Trim(),
                                    txtRemarks2.Text.Trim(),
                                    txtRemarks3.Text.Trim(),
                                    txtRemarks4.Text.Trim(),
                                    txtRemarks5.Text.Trim(),
                                    txtDate1.Text.Trim(),
                                    txtDate2.Text.Trim(),
                                    txtDate3.Text.Trim(),
                                    txtDate4.Text.Trim(),
                                    txtDate5.Text.Trim(),
                                    txtDeci1.Text.Trim(),
                                    txtDeci2.Text.Trim());

        if (ret == 0)
        {
            m_logdb.writeSucLog(SysUtil.m_functiong_product, "add product suc!");
            Jscript.AlertAndRedirect("Add succeed!", "OptProduct.aspx", this.Page);
        }
        else
        {
            m_logdb.writeFaileLog(SysUtil.m_functiong_product, "add product faile!");
            Jscript.Alert("Add failed!", this.Page);
            lblError.Text = m_productdb.ErrorMessage;
        }
    }


    protected void btnCancel_Click(object sender, EventArgs e)
    {
        this.clearText();
    }


    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("OptProduct.aspx");
    }
}
